package com.singfan.app.util;

import com.singfan.common.util.CheckUtil;
import com.singfan.common.util.GPSUtil;

import java.util.Date;
import java.util.List;

/**
 * Author: hansonghe
 * Date: 2015-08-31 10:35
 * Desc:
 */
public class RequestParamChecker {
    private static final int DAY_TIME_MS = 24 * 60 * 60 * 1000;
    public static boolean checkLongitude(String longitudeText){
        boolean result = false;

        if(CheckUtil.isDouble(longitudeText)){
            double longitude = Double.parseDouble(longitudeText);
            if(GPSUtil.isLongitude(longitude)){
                result = true;
            }
        }

        return result;
    }

    public static boolean checkLatitude(String latitudeText){
        boolean result = false;

        if(CheckUtil.isDouble(latitudeText)){
            double latitude = Double.parseDouble(latitudeText);
            if(GPSUtil.isLatitude(latitude)){
                result = true;
            }
        }

        return result;
    }

    public static boolean checkPageIndexAndSize(int pageIndex, int pageSize){
        boolean result = false;

        if (pageIndex >= 0 && pageSize > 0 && pageSize <= 100){
            result = true;
        }

        return result;
    }

    public static boolean checkAppointmentDayTime(int dayTime){
        boolean result = false;
        if (dayTime > 20150831){
            long now = System.currentTimeMillis();
            long timeAfter7Day = now + DAY_TIME_MS * 7;
            int year = dayTime / 10000;
            int month = ((dayTime % 10000) / 100) - 1;
            int day = dayTime % 100;
            long appointmentTime = new Date(year, month, day).getTime();
            if (appointmentTime > now || appointmentTime <= timeAfter7Day){
                result = true;
            }
        }

        return result;
    }

    public static boolean checkAppointmentMonthTime(int monthTime){
        return checkAppointmentDayTime(monthTime * 100);
    }

    public static boolean checkAppointmentClockTime(int clockTime){
        List<Integer> clockTimeList = AppointmentUtil.createOneDayAppointmentList();
        return clockTimeList.contains(clockTime);
    }

    public static boolean checkStarLevel(int level){
        return (level >= 1 && level <= 10);
    }
}
